package com.ruoyi.web.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.domain.vo.MonitorAreaTreeVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.ibatis.type.Alias;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 * 
 * @author ruoyi
 */
@Data
@Alias("CustomTreeSelect") // 设置别名
public class TreeSelect implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    private Long id;

    /** 节点名称 */
    private String label;

    /** 节点顺序 */
    private Integer sort;

    /** 节点禁用 */
    private boolean disabled = false;

    /**
     * '1'：监控区域，'2'：监控摄像头
     */
    @ApiModelProperty("节点类型")
    private String type;

//    /** 该区域下所拥有的摄像头 */
////    @JsonInclude(JsonInclude.Include.NON_EMPTY)
//    private List<MonitorCameraVo> cameras;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect(MonitorAreaTreeVo monitorArea)
    {
        this.id = monitorArea.getBaseId();
        this.label = monitorArea.getBaseName();
        this.sort = monitorArea.getSort();
        this.type = monitorArea.getType();
//        this.cameras = monitorArea.getCameras();
        this.children = monitorArea.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysDept dept)
    {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.disabled = StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus());
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysMenu menu)
    {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }
}
